package com.baidu.tcpDemo1;

import java.io.OutputStream;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws Exception {
        //1.创建socket 指定服务端的IP和端口
        Socket socket = new Socket(InetAddress.getLocalHost().getHostAddress(), 9999);

        //2.创建输出流管道
        OutputStream outputStream = socket.getOutputStream();

        //3.将低级管道包装成高级管道 因为是传输字符 故使用打印流来包装
        PrintStream printStream = new PrintStream(outputStream);

        //4.创建扫描器
        Scanner scanner = new Scanner(System.in);

        while (true){
            System.out.println("请输入");
            String msg = scanner.next();
            //4.使用打印流打印一行数据
            printStream.println(msg);

            //5.刷新数据
            printStream.flush();
        }
    }
}
